package org.atlantis.grosbeak.pot.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

/**
 * 把数据库中查询出来的字段的数据映射到一个字符串中。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
public class StringFieldMapper implements FieldMapper<String> {

	public static final StringFieldMapper ME = new StringFieldMapper();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.atlantis.grosbeak.pot.mapper.FieldMapper#getTypes()
	 */
	public int[] getTypes() {
		return new int[] { Types.CHAR, Types.VARCHAR, Types.LONGNVARCHAR };
	}

	public String mapField(ResultSet rs, int type, String column, boolean nullable)
			throws SQLException {
		String result = rs.getString(column);
		if (!nullable && result == null)
			return "";
		return result;
	}
}
